sroute, tiger, mapsource: ascii-ify output
authorrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Fri, 6 Feb 2004 08:17:24 +0000 (08:17 +0000)
committerrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Fri, 6 Feb 2004 08:17:24 +0000 (08:17 +0000)
gpsbabel/mapsource.c
gpsbabel/saroute.c
gpsbabel/tiger.c
gpsbabel/util.c

index 0dcbcf102559e5b562b6081cfd9dfc2c1cc046d8..dbd9b3af3012eaaa1204efdf1ece97b61382b052 100644 (file)
@@ -585,6 +585,7 @@ mps_waypoint_w(FILE *mps_file, int mps_ver, const waypoint *wpt, const int isRou
        int     icon;
        char *src;
        char *ident;
+       char *ascii_description;
        char zbuf[25];
        char ffbuf[25];
        int display = 1;
@@ -613,7 +614,8 @@ mps_waypoint_w(FILE *mps_file, int mps_ver, const waypoint *wpt, const int isRou
        icon = mps_converted_icon_number(icon, mps_ver, MAPSOURCE);
 
        /* two NULL (0x0) bytes at end of each string */
-       reclen = strlen(ident) + ((wpt->description) ? strlen(wpt->description) : 0) + 2;       
+       ascii_description = wpt->description ? str_utf8_to_ascii(wpt->description) : xstrdup("");
+       reclen = strlen(ident) + strlen(ascii_description) + 2; 
        if ((mps_ver == 4) || (mps_ver == 5)) {
                /* v4.06 & V5.0*/
                reclen += 85;                           /* "W" (1) + strlen(name) + NULL (1) + class(4) + country(sz) +  
@@ -670,9 +672,10 @@ mps_waypoint_w(FILE *mps_file, int mps_ver, const waypoint *wpt, const int isRou
                fwrite(hdr, 1 , 1, mps_file);
                fwrite(&mps_altitude, 8 , 1, mps_file);
        }
-
-       if (wpt->description) fputs(wpt->description, mps_file);
+       if (wpt->description) fputs(ascii_description, mps_file);
        fwrite(zbuf, 1, 1, mps_file);   /* NULL termination */
+       xfree(ascii_description);
+       ascii_description = NULL;
 
        if (mps_proximity == unknown_alt) {
                fwrite(zbuf, 9, 1, mps_file);
index 5a0ee80c4753c3690a946538aef431ce8de2878e..a4725ef5482faf8ea5e97fcdb48f16c34dc0044c 100644 (file)
@@ -82,8 +82,8 @@ my_read(void)
        unsigned short version;
        unsigned long count;
        unsigned long recsize;
-       unsigned char *record;
        unsigned short stringlen;
+       unsigned char *record;
        static int serial = 0;
        struct ll {
                long lat;
@@ -116,7 +116,7 @@ my_read(void)
 
        stringlen = le_read16((unsigned short *)(record + 0x1a));
        Skip(infile, stringlen - 4);
-       free(record);
+       xfree(record);
 
        /*
         * end of filename record 
@@ -151,6 +151,7 @@ my_read(void)
                        wpt_tmp->shortname = xmalloc(7);
                        sprintf( wpt_tmp->shortname, "\\%5.5x", serial++ );
                        route_add_wpt(track_head, wpt_tmp);
+                       xfree(record);
                } else {
                        Skip(infile, recsize);
                        /*
@@ -219,7 +220,7 @@ my_read(void)
                        latlon++;
                        coordcount--;
                }
-               free(record);
+               xfree(record);
        }
        /*
         * end of routing 
index f0e202bf573aa07123c8dcb4eb87abcd046e3315..865b5d7a576bd0921cefb38240ffd5eb0ab3705d 100644 (file)
@@ -170,10 +170,12 @@ tiger_disp(const waypoint *wpt)
        fprintf(file_out, "%f,%f:%s", lon, lat, pin);
        if (!nolabels) {
                char *desc = csv_stringclean(wpt->description, ":");
+               char *adesc = str_utf8_to_ascii(desc);
                if (global_opts.synthesize_shortnames)
-                       desc = mkshort(mkshort_whandle, desc);
-               fprintf(file_out, ":%s", desc);
+                       adesc = mkshort(mkshort_whandle, adesc);
+               fprintf(file_out, ":%s", adesc);
                xfree(desc);
+               xfree(adesc);
        }
        fprintf(file_out, "\n");
 }
index 309f80fad6645a778b7f7695c5f0b9ccf261c211..f4628e31617096c4362a7bb473ba8c3e247533ab 100644 (file)
@@ -193,7 +193,7 @@ xrealloc(void *p, size_t s)
 
        if (!o) {
                fatal("gpsbabel: Unable to realloc %d bytes of memory.\n", s);
-                       }
+       }
 
        return o;
 }